﻿# 检查AutoCAD注册表，列出已经删除的文件，输入Y，删除其所在的AutoCAD注册表。

if (Test-Path -Path 'HKCU:\Software\Autodesk\AutoCAD') {
    $array = @()
    foreach ($AutoCADVersion in Get-ChildItem -Path 'HKCU:\Software\Autodesk\AutoCAD') {
        $CurVer = (Get-ItemProperty -Path "HKCU:\$AutoCADVersion").CurVer
        foreach ($CadApp in Get-ChildItem -Path "HKCU:\$AutoCADVersion\$CurVer\Applications") {
            $CadPath = (Get-ItemProperty -Path "HKCU:\$CadApp").LOADER
            if (-not (Test-Path -Path $CadPath -PathType Leaf)) {
                Write-Host $CadPath -ForegroundColor Green
                $array += $CadApp
            }
        }
    }

    $input = Read-Host "上文的路径为已经删除的文件，是否删除其所在的AutoCAD注册表？(Y/N)"
    if ($input.ToUpper() -eq "Y") {
        Write-Host "用户输入 Y，开始执行操作..." -ForegroundColor Green
        foreach($ii in $array)
        {
            Remove-Item -Path $ii.PSPath -Recurse -Force
        }
    } else {
        Write-Host "用户输入非 Y，退出程序..." -ForegroundColor Yellow
    }
}